<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>累计访问人次明细</title>
  <link rel="stylesheet" href="../../mobile_static/css/element.css">
  <link rel="stylesheet" href="../../mobile_static/css/base.css">
  <link rel="stylesheet" href="../../mobile_static/css/operationIndexAnalysis/cumulativeNumberOfVisits.css">
  <script src="../../mobile_static/js/vue.js"></script>
  <script src="../../mobile_static/js/axios.js"></script>

</head>

<body>
  <div id="app">
    <div class="app-content">
      <!-- 导航栏 -->
      <div class="top-bar">
        <div>
          <el-button @click="backHome" type="primary" plain>返回</el-button>
        </div>
      </div>
      <!-- 表格 -->
      <div class="table-box">
        <!-- 表格标题 -->
        <div class="table-title">
          <h2>应用名称：{{popName}}</h2>
          <div class="download-box">
            <el-button type="primary" @click="download">下载</el-button>
          </div>
          <div class="search-box">
            <el-input prefix-icon="el-icon-search" v-model="searchValue" placeholder="按用户名搜索" @change="search">
            </el-input>
          </div>
          <div class="select-box">
            <el-date-picker value-format="yyyy-MM-dd" v-model="value" @change="dateChange" type="daterange"
              unlink-panels range-separator="至" start-placeholder="请选择开始日期" end-placeholder="请选择结束日期">
            </el-date-picker>
          </div>
          <ul class="ul-box">
            <li :class="{'selected':isSelect == 1}" @click="isSelect=1">近7天</li>
            <li :class="{'selected':isSelect == 2}" @click="isSelect=2">近30天</li>
            <li :class="{'selected':isSelect == 3}" @click="isSelect=3">本年</li>
          </ul>
        </div>
        <!-- 表格主体 -->
        <div class="table-main">
          <el-table :data="tableData" stripe style="width: 100%" v-loading="loading" border :header-cell-style="{background: 'linear-gradient(180deg, #FAFAFA 0%, #F1F1F1 100%)',fontSize:'16px',fontWeight:'bold',color:'#000000'}">
            <el-table-column prop="g0userid" label="登录账号" width="160">
            </el-table-column>
            <el-table-column prop="g0username" label="用户姓名" width="120">
            </el-table-column>
            <el-table-column prop="g0full_department_name" label="所属企业" min-width="350">
            </el-table-column>
            <el-table-column prop="g0accessdate" label="访问日期" width="260">
            </el-table-column>
            <el-table-column prop="k0visit_cnt" label="访问次数" width="120">
            </el-table-column>
          </el-table>
        </div>
        <!-- 分页 -->
        <div class="paging-box">
          <div class="block">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
              :current-page="thisPage" :page-sizes="[10, 20, 30, 40]" :page-size="size"
              layout="total, sizes, prev, pager, next, jumper" :total="length">
            </el-pagination>
          </div>
        </div>
      </div>
    </div>
  </div>
</body>

</html>
<script src="../../mobile_static/js/element.js"></script>
<script type="module">
  import { postOneId, getOneIdDownload } from '../../mobile_static/axios/axios.config.js'
  new Vue({
    el: "#app",
    data() {
      return {
        loading: false,

        isSelect: 5,
        timeValue: "", //日期value值
        value: '',//日期选择值
        searchValue: "",
        startDate: "",
        endDate: "",
        size: 10,
        thisPage: 1,
        tableData: [

        ],
        length: "",
        code: "",
        class: "",
        popName: '',
        g0module_type_code: '',
        g0app_type_code: ''
      }
    },
    created() {
      let array = window.location.search.slice(1).split("&")
      this.code = array[0].split("=")[1]
      this.class = array[1].split("=")[1]
      this.popName = decodeURI(array[2].split("=")[1])
      this.isSelect = array[3].split("=")[1]
      this.startDate = array[4].split("=")[1]
      this.endDate = array[5].split("=")[1]
      this.g0module_type_code = array[6].split("=")[1]
      this.g0app_type_code = array[7].split("=")[1]
      if (this.isSelect == 5) {
        this.value = [this.startDate, this.endDate]
      }
    },
    mounted() {
      // this.CumulativeVisits()
    },
    watch: {
      //针对日期改变做监听
      isSelect(val) {
        let nowDate = new Date();
        if(val!=5){
          this.endDate = `${nowDate.getFullYear()}-${this.ZeroComplement(nowDate.getMonth() + 1)}-${this.ZeroComplement(nowDate.getDate())}`
        }
        if (val === 1) {
          this.value = []
          var date1 = new Date();
          //今天时间
          var time1 = date1.getFullYear() + "-" + (date1.getMonth() + 1) + "-" + date1.getDate()
          var date2 = new Date(date1);
          date2.setDate(date1.getDate() + -7);
          //num是正数表示之后的时间，num负数表示之前的时间，0表示今天
          var time2 = date2.getFullYear() + "-" + this.ZeroComplement(date2.getMonth() + 1) + "-" + this.ZeroComplement(date2.getDate());
          this.startDate = time2
          // this.RequestFourCrazy()
        } else if (val === 2) {
          this.value = []
          let day_30 = new Date().setMonth((new Date().getMonth() - 1));    //日期是30天前的对应时间戳
          day_30 = new Date(day_30);       //转换成标准时间
          let y = day_30.getFullYear();    //年
          let m = day_30.getMonth() + 1;    //月
          let d = day_30.getDate();        //日
          if (m < 10) {
            m = '0' + m;
          }
          if (d < 10) {
            d = '0' + d;
          }
          day_30 = y + '-' + m + '-' + d;    //日期是30天前的对应字符串 xxxx-xx-xx　
          this.startDate = day_30
          // this.RequestFourCrazy()
        } else if (val === 3) {
          this.value = []
          this.startDate = nowDate.getFullYear() + "-01-01"
          // this.RequestFourCrazy()
        }
        if (val) {
          this.CumulativeVisits()
        }
      }
    },
    methods: {
      backHome() {
        window.history.back()
      },
      handleSizeChange(val) {
        this.size = val
        this.CumulativeVisits()
      },
      //页数改变调用
      handleCurrentChange(val) {
        this.thisPage = val
        this.CumulativeVisits()
      },
      //日期选择框
      dateChange() {
        if (this.value) {
          this.startDate = this.value[0]
          this.endDate = this.value[1]
          this.isSelect = 0
        } else {
          this.startDate = "2021-01-01"
          this.endDate = "2022-03-08"
          this.isSelect = window.location.search.slice(1).split("&")[3].split("=")[1]
        }

        this.CumulativeVisits()
      },
      search() {
        this.thisPage = 1
        this.CumulativeVisits()
      },
      //请求累计访问人次数据
      CumulativeVisits() {
        this.loading = true
        postOneId("fwlpvmxb2_qdhzb00", {
          pageSize: this.size,
          pageNum: this.thisPage,
          startDate: this.startDate,
          endDate: this.endDate,
          g0enterpriseCode: this.code,
          g0username: this.searchValue,
          g0mduleclass: this.class,
          g0moduleTypeCode: this.g0module_type_code,
          g0appTypeCode: this.g0app_type_code
        }).then(res => {
          this.loading = false
          res = JSON.parse(res.data.msg);
          console.log(res, "请求累计访问人次数据成功");
          if (res.total) {
            this.tableData = res.data
          } else {
            this.tableData = []
          }
          this.length = res.total
        })
      },
      //下载
      download() {
        if (this.length > 50000) {
          this.$notify.error({
            title: '下载失败',
            message: "下载数据条数不能超过50000条",
          });
          return
        }
        this.loading = true
        getOneIdDownload("fwlpvmxb2_qdhzb00Export", {
          pageSize: this.length,
          pageNum: 1,
          startDate: this.startDate,
          endDate: this.endDate,
          g0enterpriseCode: this.code,
          g0username: this.searchValue,
          g0moduleTypeCode: this.g0module_type_code,
          g0appTypeCode: this.g0app_type_code,
          g0mduleclass: this.class,
        }).then(res => {
          if (!res) {
            return
          }
          this.loading = false

          let url = window.URL.createObjectURL(res.data)
          let link = document.createElement("a")
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', '累计访问人次明细.xlsx')
          document.body.appendChild(link)
          link.click()
        })
      },
      //补零函数
      ZeroComplement(num) {
        if (num < 10) {
          return "0" + num;
        } else {
          return num;
        }
      }
    }
  })
</script>